from django import forms
from models import Interface

class BasicSettingsForm(forms.Form):
    hostname = forms.CharField(max_length=100,help_text="Hostname without domain part.Example: oms",initial="oms")
    domain = forms.CharField(max_length=100,help_text="Domain this host belongs to.Example: example.com",initial="local")
    primary_dns = forms.IPAddressField(required=False,help_text="Primary DNS ip address",initial="")
    secondary_dns = forms.IPAddressField(required=False,help_text="Secondary DNS ip address",initial="")
    gateway = forms.IPAddressField(required=False,help_text="Default gateway")

class InterfacesForm(forms.ModelForm):
    name = forms.CharField(widget=forms.HiddenInput)
    enabled = forms.BooleanField(widget=forms.CheckboxInput(attrs={"onclick":"javascript:setup_interface_fields(this)"}),required=False)
    dhcp = forms.BooleanField(widget=forms.CheckboxInput(attrs={"onclick":"javascript:setup_interface_fields(this)"}),required=False)
    class Meta:
        model = Interface
    class Media:
        js = ('js/interfaces.js',)
    def __init__(self,*args,**kwargs):
        super(InterfacesForm, self).__init__(*args, **kwargs)
        if not self.instance.enabled or self.instance.dhcp:
            self.fields['ip'].widget.attrs={'disabled':'true'}
            self.fields['mask'].widget.attrs={'disabled':'true'}


